/*
 * Explosion.cpp
 *
 *  Created on: 31/10/2011
 */

#include "Explosion.h"
#include "../../common/lib/SDL_rotozoom.h"
#include "../../common/utils/SurfaceUtils.h"

#define DEFAULT_EXPLOSION_DAMAGE 0
#define PIXELS_PER_MOVE 8

Explosion::Explosion(int posX, int posY, Widget *parent) :
	WidgetMovimiento(EXPLOSION,posX, posY,std::string(EXPLOTION_IMAGE), parent,DEFAULT_EXPLOSION_DAMAGE),WidgetSonido(EXPLOTION_DEFAULT_SOUND_EFFECT) {

	this->maxDuration = EXPLOSION_DURATION;
	this->timeAlive = 0;
	playSound();
}

Explosion::Explosion(DTOExplosion* dto, Widget* parent) :
	WidgetMovimiento(EXPLOSION,dto->x, dto->y,std::string(EXPLOTION_IMAGE), parent),WidgetSonido(EXPLOTION_DEFAULT_SOUND_EFFECT) {

	this->maxDuration = EXPLOSION_DURATION;
	this->timeAlive = 0;

	playSound();
}

void Explosion::resolve() {

	if (drawable) {
		//Timer to get seconds between frames
		if (!timer.is_started()) {
			timer.start();
		}

		float secsPerFrame = timer.get_ticks() / 1000.0;
		timeAlive += secsPerFrame;
		if (timeAlive >= maxDuration) {
			this->drawable = false;
			timer.stop();
		}
	}

}
void Explosion::handleColision(WidgetMovimiento* with){}

